package com.lhl.api.sample.controller;

import com.lhl.api.sample.domain.DemoDTO;
import com.lhl.api.sample.domain.DemoVO;
import com.lhl.api.sample.mapstruct.DemoMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/**
 * @className: DemoController
 * @description: TODO 类描述
 * @author: king
 * @date: 2020-09-09 16:39
 **/
@RestController
@RequestMapping("/sample")
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DemoController {

    private final DemoMapper demoMapper;

    @GetMapping("/searchAll")
    public List<DemoDTO> searchAll(){
        log.debug("------------------------------");
        List<DemoDTO> ds = new ArrayList<>();
        ds.add(new DemoDTO("KING", LocalDate.of(1979,10,18),41));
        ds.add(new DemoDTO("Cissy", LocalDate.of(1982,2,18),38));
        ds.add(new DemoDTO("lhl", LocalDate.of(2013,12,23),7));
        return ds;
    }

    @PostMapping("/create")
    public DemoDTO create(@RequestBody DemoVO vo){
        return demoMapper.toDto(vo);
    }
}